package edu.nf.ch10.controller;

import edu.nf.ch10.service.PublishService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author wangl
 * @date 2025/9/19
 */
@RestController
public class AdminController {

    private final static Logger log = LoggerFactory.getLogger(AdminController.class);

    private PublishService service;

    public AdminController(PublishService service) {
        this.service = service;
    }

    @PostMapping("/message/{topic}")
    public String send(@PathVariable("topic")  String topic,
            @RequestParam("message") String message) {
        log.info("消息：{}", message);
        service.sendMessage(topic, message);
        return "success";
    }
}